package com.example.matriculagaleraufba;


import java.util.StringTokenizer;

import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.app.ListFragment;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ListView;
import android.widget.Toast;

public class sessaoActivity extends Activity 
							implements ListCursos.OnCursoSelecionadoListener{

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.tela_sessao);
	    // TODO Auto-generated method stub
	    
 
	   //Toast.makeText(getApplicationContext(), "Mostrando FragmentEscolherCurso ", Toast.LENGTH_SHORT).show();

	   FragmentTransaction ft = getFragmentManager().beginTransaction();	    
	   FragmentEscolherCurso fec = new FragmentEscolherCurso();
	   ft.replace(R.id.opcaoEscolhida,fec);
	    ft.addToBackStack(null);

	   
	   

	   //Toast.makeText(getApplicationContext(), "Mostrando FragmentEscolherOpcoes ", Toast.LENGTH_SHORT).show();

	   FragmentOpcoes fop = new FragmentOpcoes();
	   ft.replace(R.id.opcoes,fop);
	    ft.addToBackStack(null);

	   
	  

	   ft.commit();
	   
	  
	   
	   

	/*   // inativar este botao se usuario nao escolheu curso.
	   final Button btMontarHorario = (Button) findViewById(R.id.btMontarHorario);
       btMontarHorario.setOnClickListener(new View.OnClickListener() {
           public void onClick(View v) {
               // Perform action on click
        	   FragmentTransaction ft = getFragmentManager().beginTransaction();	    
        	   FragmentMontarHorario fmh = new FragmentMontarHorario();
        	   ft.add(R.id.opcaoEscolhida,fmh);
        	   ft.commit();

           	
           }
       });*/
	    
	}
	

	
	public void mostraMontarHorario(View view){
		//   Toast.makeText(getApplicationContext(), "Mostrando FragmentMontarHorario ", Toast.LENGTH_SHORT).show();

		 FragmentTransaction ft = getFragmentManager().beginTransaction();	    
  	   FragmentMontarHorario fmh = new FragmentMontarHorario();
  	   ft.replace(R.id.opcaoEscolhida,fmh);
  	    ft.addToBackStack(null);

  	   ft.commit();
		
	}
	
	public void mostraEscolherCurso(){
		  // Toast.makeText(getApplicationContext(), "Mostrando FragmentEscolherCurso ", Toast.LENGTH_SHORT).show();

		 FragmentTransaction ft = getFragmentManager().beginTransaction();	    
	  	   FragmentEscolherCurso fec = new FragmentEscolherCurso();
	  	   ft.replace(R.id.opcaoEscolhida,fec);
	  	    ft.addToBackStack(null);

	  	   ft.commit();
		
	}
	
	public void mostraBusca(View view){
		  // Toast.makeText(getApplicationContext(), "Mostrando FragmentBusca ", Toast.LENGTH_SHORT).show();

		 FragmentTransaction ft = getFragmentManager().beginTransaction();	    
	  	   FragmentBusca fb = new FragmentBusca();
	  	   ft.replace(R.id.opcaoEscolhida,fb);
	  	    ft.addToBackStack(null);

	  	   ft.commit();
		
	}
	
	public void geraHorario(View view){
		  // Toast.makeText(getApplicationContext(), "Mostrando FragmentgeraHorario ", Toast.LENGTH_SHORT).show();

		FragmentTransaction ft = getFragmentManager().beginTransaction();	    
	  	   FragmentHorario fb = new FragmentHorario();
	  	   ft.replace(R.id.opcaoEscolhida,fb);
	  	    ft.addToBackStack(null);

	  	   ft.commit();		
	}



	@Override
	public void onCursoSelecionado(int position) {
		View view = null;
		// TODO Auto-generated method stub
		ListCursos lc = (ListCursos) getFragmentManager().findFragmentById(R.id.cursosFragment);
		String cursoSelecionado = (String) lc.getListView().getItemAtPosition(position);
		Log.i("OnCursoSelecionado",cursoSelecionado);
		
		StringTokenizer tokens = new StringTokenizer(cursoSelecionado, " - ");
		String codigo = tokens.nextToken();
		Log.i("OnCursoSelecionado - codigo",codigo);
		/*String curso = tokens.nextToken("");
		Log.i("OnCursoSelecionado - curso",curso);*/
		
		
		
		/*mostraMontarHorario(view);
		mostraEscolherCurso();
		

		ListDisciplinas ld = (ListDisciplinas) getFragmentManager().findFragmentById(R.id.disciplinasFragment);
		ld.codigoCurso = codigo;
		Log.i("OnCursoSelecionado","setado LD codigoCurso");

		Log.i("OnCursoSelecionado","mostraMontarHorario");*/


		

		
	}
	

}